package br.com.array.android.ma.controller;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import br.com.array.android.ma.R;
import br.com.array.android.ma.model.ItemAlertaModel;

import java.util.List;

/**
 * Created by leonardo.neves on 09/05/2014.
 *
 */
public class ItemAlertaAdapter extends BaseAdapter {

    private List<ItemAlertaModel> itens;
    private LayoutInflater inflater;

    public ItemAlertaAdapter(Context context, List<ItemAlertaModel> itens) {
        this.inflater = LayoutInflater.from(context);
        this.itens = itens;
    }

    @Override
    public int getCount() {
        return itens.size();
    }

    @Override
    public Object getItem(int position) {
        return itens.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            convertView = inflater.inflate(R.layout.item_alarme, null);
            holder = new ViewHolder();

            holder.tvData = (TextView) convertView.findViewById(R.id.value_data);
            holder.tvHora = (TextView) convertView.findViewById(R.id.value_hora);
            holder.tvTempoDecorrido = (TextView) convertView.findViewById(R.id.value_percentual);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        ItemAlertaModel item = itens.get(position);
        holder.tvData.setText(item.getData());
        holder.tvHora.setText(item.getHora());
        holder.tvTempoDecorrido.setText(item.getTempoDecorrido());

        return convertView;
    }

    static class ViewHolder {
        TextView tvData;
        TextView tvHora;
        TextView tvTempoDecorrido;
    }
}
